<template>
  <el-col class="bill">
    <el-col class="title">入库管理</el-col>
    <el-col class="tabs">
      <div
        :class="inventory === '茶叶' ? 'current' : ''"
        @click="handleClick('茶叶')"
      >
        茶叶
      </div>
      <div
        :class="inventory === '礼盒' ? 'current' : ''"
        @click="handleClick('礼盒')"
      >
        礼盒
      </div>
    </el-col>
    <el-col class="search">
      <el-input
        placeholder="输入商品名称"
        suffix-icon="el-icon-search"
        v-model="name"
      ></el-input>
      <el-date-picker
        type="daterange"
        range-separator="-"
        start-placeholder="开始日期"
        end-placeholder="结束日期"
        v-model="dateTime"
        @change="pickerChange"
      >
      </el-date-picker>
      <el-button type="primary" @click="get_storageList">搜索</el-button>
    </el-col>

    <el-col class="controls">
      <div @click="goto_storage">新增入库</div>
    </el-col>

    <el-table :data="productList" border stripe size="small">
      <el-table-column
        v-for="col in columns"
        :prop="col.id"
        :key="col.id"
        :label="col.label"
        :width="col.width"
        show-overflow-tooltip
      ></el-table-column>
    </el-table>
    <div class="class_bottom">
      <el-pagination
        @current-change="handleCurrent"
        :page-size="15"
        layout="total, prev, pager, next"
        :total="total"
      ></el-pagination>
    </div>
  </el-col>
</template>
<script>
export default {
  data() {
    return {
      inventory: "茶叶",
      productList: [],
      columns: [
        {
          id: "index",
          label: "序号",
          width: "80",
        },
        {
          id: "good_name",
          label: "商品名称",
        },
        {
          id: "number",
          label: "入库数量",
        },
        {
          id: "stor_time",
          label: "入库时间",
        },
      ],
      total: 0,
      page: 1,
      name: "",
      start: "",
      end: "",
      dateTime: "",
      collectShow: false,
    };
  },
  mounted() {
    this.get_storageList();
  },
  methods: {
    handleClick(tab) {
      this.inventory = tab;
      this.page = 1;
      this.name = "";
      this.start = "";
      this.end = "";
      this.get_storageList();
    },
    pickerChange(value) {
      this.start = value ? this.getTime(value[0]) : "";
      this.end = value ? this.getTime(value[1]) : "";
    },
    getTime(time) {
      let date = new Date(time);
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();
      month >= 1 && month <= 9 ? (month = "0" + month) : "";
      day >= 0 && day <= 9 ? (day = "0" + day) : "";
      return year + "-" + month + "-" + day;
    },
    goto_storage() {
      this.$router.push({
        path: "/home/addStorage",
      });
    },
    handleCurrent(val) {
      this.page = val;
      this.get_storageList();
    },
    async get_storageList() {
      let data = {
        good_name: this.name,
        class: this.inventory,
        start: this.start,
        end: this.end,
        page: this.page,
      };
      let res = await this.$store.dispatch("crm_storageList", data);
      if (!res.code) {
        this.total = res.data.total;
        res.data.data.forEach((item, index) => {
          item.index = index + 1;
        });
        this.productList = res.data.data;
      }
    },
  },
};
</script>
<style lang="scss" >
.bill {
  padding: 30px;
  text-align: left;

  .tabs {
    display: flex;
    align-items: center;
    border-bottom: #999999 solid 1px;

    div {
      padding: 30px;
      color: #333333;
      font-size: 20px;
      font-weight: bold;
      cursor: pointer;
    }

    .current {
      padding: 30px 30px 26px;
      border-bottom: #339ef9 solid 4px;
    }
  }

  .search {
    display: flex;
    align-content: center;
    justify-content: space-between;
    padding: 20px 0;

    .el-input,
    .el-date-editor {
      width: 46%;
    }
  }

  .controls {
    display: flex;
    align-items: center;
    margin-bottom: 20px;

    div {
      background-color: #409eff;
      background-image: none;
      border-radius: 4px;
      box-sizing: border-box;
      font-size: 14px;
      color: #ffffff;
      height: 40px;
      line-height: 40px;
      outline: 0;
      padding: 0 15px;
      margin-right: 20px;
      cursor: pointer;
    }
  }
}
</style>